package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysUserClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysUserClassMapper;
import com.ruoyi.system.service.ISysUserClassService;
import org.springframework.util.CollectionUtils;

/**
 * 用户课程链接Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-27
 */
@Service
public class SysUserClassServiceImpl implements ISysUserClassService
{
    @Autowired
    private SysUserClassMapper sysUserClassMapper;

    /**
     * 查询用户课程链接
     *
     * @param classId 用户课程链接主键
     * @return 用户课程链接
     */
    @Override
    public SysUserClass selectSysUserClassByClassId(Long classId)
    {
        return sysUserClassMapper.selectSysUserClassByClassId(classId);
    }

    /**
     * 查询用户课程链接列表
     *
     * @param sysUserClass 用户课程链接
     * @return 用户课程链接
     */
    @Override
    public List<SysUserClass> selectSysUserClassList(SysUserClass sysUserClass)
    {
        return sysUserClassMapper.selectSysUserClassList(sysUserClass);
    }

    /**
     * 根据用户主键查询用户课程链接表
     * @param userId
     * @return
     */
    @Override
    public List<SysUserClass> selectSysUserClassListByUserId(Long userId) {
        return sysUserClassMapper.selectSysUserClassListByUserId(userId);
    }

    /**
     * 新增用户课程链接
     *
     * @param sysUserClass 用户课程链接
     * @return 结果
     */
    @Override
    public int insertSysUserClass(SysUserClass sysUserClass)
    {
        return sysUserClassMapper.insertSysUserClass(sysUserClass);
    }

    /**
     * 根据用户新增用户课程链接表
     * @param sysUser
     * @retur
     */
    @Override
    public int insertSysUserClassBySysUser(SysUser sysUser) {
        int status = 0;
        if (!CollectionUtils.isEmpty(sysUser.getUserClassList())){
            for (int i = 0;i < sysUser.getUserClassList().size();i++){
                SysUserClass sysUserClass = new SysUserClass();
                //用户主键
                sysUserClass.setUserId(sysUser.getUserId());
                //课程主键
                sysUserClass.setClassId(sysUser.getUserClassList().get(i).getClassId());
                //用户课程新增方法
                status += this.insertSysUserClass(sysUserClass);
            }
        }
        return status;
    }

    /**
     * 修改用户课程链接
     *
     * @param sysUserClass 用户课程链接
     * @return 结果
     */
    @Override
    public int updateSysUserClass(SysUserClass sysUserClass)
    {
        return sysUserClassMapper.updateSysUserClass(sysUserClass);
    }

    /**
     * 批量删除用户课程链接
     *
     * @param classIds 需要删除的用户课程链接主键
     * @return 结果
     */
    @Override
    public int deleteSysUserClassByClassIds(Long[] classIds)
    {
        return sysUserClassMapper.deleteSysUserClassByClassIds(classIds);
    }

    /**
     * 删除用户课程链接信息
     *
     * @param classId 用户课程链接主键
     * @return 结果
     */
    @Override
    public int deleteSysUserClassByClassId(Long classId)
    {
        return sysUserClassMapper.deleteSysUserClassByClassId(classId);
    }

    /**
     * 根据用户主键删除课程链接信息
     * @param userId
     * @return
     */
    @Override
    public int deleteSysUserClassByUserId(Long userId) {
        return sysUserClassMapper.deleteSysUserClassByUserId(userId);
    }
}